package com.xinshujia.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xinshujia.dto.AlarmRecordDTO;
import com.xinshujia.entity.AlarmRecordEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * *************************************
 * *   @author: 野狼上校               **
 * *   @since: 2024-07-19 14:20       **
 * *   @version: 1.0                  **
 * *************************************
 * <p>
 * 预警记录持久化接口
 */
@Mapper
public interface AlarmRecordDao extends BaseMapper<AlarmRecordEntity> {
    /**
     * 预警次数排序
     */
    @Select("SELECT COUNT(*) AS alarmCount, bar.device_guid, bd.product_line, bd.machine_name FROM auth_device bd, blade_alarm_record bar WHERE bar.device_guid = bd.device_guid;")
    List<AlarmRecordDTO> getAlarmRecords();

    /**
     * 根据Device_guid查询预警记录(多条)
     */
    @Select("SELECT bar.*, bd.product_line, bd.machine_name FROM auth_device bd, blade_alarm_record bar WHERE bar.device_guid = bd.device_guid AND bd.device_guid = #{deviceGuid} ORDER BY bar.create_time DESC;")
    List<AlarmRecordDTO> getAlarmRecordsByDeviceGuid(@Param("deviceGuid") String deviceGuid);

    /**
     * 根据Id查询
     */
    @Select("SELECT bar.*, bd.product_line, bd.machine_name FROM auth_device bd, blade_alarm_record bar WHERE bar.device_guid = bd.device_guid AND bar.id = #{id};")
    AlarmRecordDTO getAlarmRecordById(@Param("id") Long id);


}
